#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#define int long long
#define x first 
#define y second  
using namespace std;
const int N = 2e6 + 10;
int arr[N];
//差分会超时,每次1操作必会涉及第一个数字 每次2操作必回涉及最后一个数字 
//只考虑最后一个数和第一个数字即可 
void solve()
{
    int n,q;
    cin >> n >> q;
    int ans1 = 0;
    int ans2 = 0;
    while(q -- )
    {
        int k,x,y;
        cin >> k >> x >> y;
        if(k == 1)
        {
           ans1 += y;
           if(x == n) ans2 += y;
        }
        else 
        {
            ans2 -= y;
            if(x == n) ans1 -= y;
        }
    }
    cout << max(abs(ans1),abs(ans2)) << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t = 1;
    while(t -- )  solve();
    return 0;
}